package com.ichoice.rabbit.server.service;

import com.ichoice.rabbitmq.rpc.helper.RpcRabbit;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * @author xianrensawang
 * @since 2021/1/28
 */
@Service
public class LoginImpl implements Login {
    @Resource
    private RpcRabbit rpcRabbit;

    @Override
    public String login(String userName, String password) throws InterruptedException {
        System.out.println("已经接收到消息队列消息");
        Thread.sleep(3000);
        return "{\"name\":pdd,\"age\":12}";
    }

    @Override
    public String getName(Integer age) throws InterruptedException {
        System.out.println("执行了入参:"+age);
        return "pdd:" + System.currentTimeMillis();
    }

    @Override
    public User user(User user) throws InterruptedException {
        Thread.sleep(3000);
        return user;
    }

    @Override
    public List<User> userList(User user) {
        return Collections.singletonList(user);
    }

    @Override
    public Integer getAge(Long age) throws InterruptedException {
        Thread.sleep(3000);
        return 1;
    }

    @Override
    public List<User> userList1(List<User> userList) {
        return userList;
    }

    /**
     * 广播登录信息
     */
    @Override
    public void fanoutLogin() {
        String message = "我已经登录完成了";
        rpcRabbit.fanout(message);
    }

    @Override
    public void fanoutUser() {
        User user = new User();
        user.setName("pdd");
        user.setSex("101");
        rpcRabbit.fanout(user);
    }


}
